﻿namespace Service.Framework.Utils
{

    /// <summary>
    /// 获取一般类名
    /// </summary>
    public static class GenericTypeUtil
    {
        public static String GetGenericTypeName(this Type type)
        {
            var typeName = string.Empty;

            if (type.IsGenericType)
            {
                var genericTypes = string.Join(",", type.GetGenericArguments().Select(t => t.Name).ToArray());
                typeName = $"{type.Name.Remove(type.Name.IndexOf('`'))}<{genericTypes}>";
            }
            else
            {
                typeName = type.Name;
            }

            return typeName;
        }

        public static String GetGenericTypeName(this Object @object)
        {
            return @object.GetType().GetGenericTypeName();
        }
    }
}
